package uno;
import java.io.IOException;
import java.util.ArrayList;
//Colors: 0 Red; 1 Green; 2 Blue; 3 Yellow
//Numbers: 0-9 Numbers; 10 Skip; 11 Draw 2; 12 Reverse; 13 Any Color; 14 Any Color Draw 4;
import java.util.Scanner;

public class Game {
        public ArrayList<Player> players = new ArrayList<Player>();
        int Players = 0, Cards = 0;
        Scanner keyboard = new Scanner(System.in);
        Game(int importedPlayers, int importedCards){
                Players = importedPlayers;
                Cards = importedCards;
                for(int count = 0; count < Players; count ++){
                        Player player = new Player(Cards);
                        players.add(player);
                }
        }
        public int start(){
                CardGenerator generator = new CardGenerator();
                Card currentCard = generator.getCard();
                if(currentCard.CardColor==-1){
                        currentCard.CardColor = 0;
                }
                Testing test = new Testing();
//              System.out.println("First card is: "+test.printCard(currentCard));
                CurrentPlayer currentPlayer = new CurrentPlayer(players.size());
                int count = 0;
                do{
                        //System.out.println("----------------------------------------------------------");
                        //System.out.println("Current card is: "+test.printCard(currentCard));
                        currentCard = players.get(currentPlayer.getCurrentPlayer()).playerTurn(currentCard);
                        
                        if(currentCard.CardNumber >= 0 && currentCard.CardNumber <= 9){
                                currentPlayer.nextPlayer();
                        }
                        
                        if(currentCard.CardNumber == 10){ //If current card is skip
                                currentPlayer.nextPlayer();
                                currentPlayer.nextPlayer();
                        }
                        
                        if(currentCard.CardNumber == 11){ //If current card is draw 2
                                currentPlayer.nextPlayer();
                                players.get(currentPlayer.getCurrentPlayer()).PlayerDraw(2);
                                currentPlayer.nextPlayer();
                        }
                        
                        if(currentCard.CardNumber == 12){
                                currentPlayer.switchDirections();
                                currentPlayer.nextPlayer();
                        }
                        
                        if(currentCard.CardNumber == 13){
                                currentPlayer.nextPlayer();
                        }
                        
                        if(currentCard.CardNumber == 14){
                                currentPlayer.nextPlayer();
                                players.get(currentPlayer.getCurrentPlayer()).PlayerDraw(4);
                                currentPlayer.nextPlayer();
                        }
                        count++;        
                        //System.out.println("It is now Player "+currentPlayer.getCurrentPlayer()+"'s turn");
//                      try {
//                              System.in.read();
//                      } catch (IOException e) {
//                              
//                              e.printStackTrace();
//                      }
                }while(currentCard.CardColor != -2);
                //System.out.println("The game took "+count+" turns.");
                return count;
        }
}